// -----------------------------------------------------------------------
//  <copyright file="CultureMiddleware.cs" company="LiuliuSoft">
//      Copyright (c) 2022-2025 DaprPlus. All rights reserved.
//  </copyright>
//  <site>https://dapr.plus</site>
//  <last-editor>郭明锋</last-editor>
//  <last-date>2025/1/14 22:46</last-date>
// -----------------------------------------------------------------------

using System.Globalization;

namespace DaprPlus.AspNetCore.Middleware;

public class CultureMiddleware(RequestDelegate next) 
    : MiddlewareBase(next)
{
    private readonly RequestDelegate _next = next;

    /// <summary>
    /// 执行中间件拦截逻辑
    /// </summary>
    /// <param name="context">Http上下文</param>
    /// <returns></returns>
    public override Task InvokeAsync(HttpContext context)
    {
        var culture = new CultureInfo("en");
        CultureInfo.DefaultThreadCurrentCulture = culture;
        CultureInfo.DefaultThreadCurrentUICulture = culture;
        CultureInfo.CurrentCulture = culture;
        CultureInfo.CurrentUICulture = culture;

        return _next(context);
    }
}
